<div id="script-list-option-groups" class="list-option-groups">
	<div id="script-list-sort" class="list-option-group"><%=t('scripts.listing_sort_label')%>
		<ul>
			<% if action_name == 'search' %>
				<%=script_list_link(t('scripts.listing_sort_relevance'), nil, params[:site], params[:set], @set)%>
				<%=script_list_link(t('scripts.listing_sort_daily_installs'), 'daily_installs', params[:site], params[:set], @set)%>
			<% elsif defined?(@set) && !@set.nil? && !@set.default_sort.nil? %>
				<%=script_list_link(t('scripts.listing_sort_daily_installs'), 'daily_installs', params[:site], params[:set], @set)%>
			<% else %>
				<%=script_list_link(t('scripts.listing_sort_daily_installs'), nil, params[:site], params[:set], @set)%>
			<% end %>
			<%=script_list_link(t('scripts.listing_sort_total_installs'), 'total_installs', params[:site], params[:set], @set)%>
			<%=script_list_link(t('scripts.listing_sort_ratings'), 'ratings', params[:site], params[:set], @set)%>
			<%=script_list_link(t('scripts.listing_sort_created_date'), 'created', params[:site], params[:set], @set)%>
			<%=script_list_link(t('scripts.listing_sort_updated_date'), 'updated', params[:site], params[:set], @set)%>
			<%=script_list_link(t('scripts.listing_sort_name'), 'name', params[:site], params[:set], @set)%>
		</ul>
	</div>

	<% if !by_sites.nil? %>
		<div id="script-list-filter" class="list-option-group"><%=t('scripts.listing_filter_by_site_label')%>
			<ul>
				<%=script_list_link(t('scripts.listing_filter_by_site_disable'), params[:sort], nil, params[:set])%>
				<% current_site_is_top = false
				(0..9).each do |i|
					break if by_sites[i].nil?
					dt = by_sites[i][0]
					if dt.nil?
						current_site_is_top = true if params[:site] == '*' %>
						<%=script_list_link(t('scripts.listing_filter_by_site_all_sites'), params[:sort], '*', params[:set], @set)%>
					<% else
						current_site_is_top = true if dt == params[:site] %>
						<%=script_list_link(dt, params[:sort], dt, params[:set], @set)%>
					<% end %>
				<% end %>
				<% if !current_site_is_top and !params[:site].nil? and !scripts.empty? %>
					<%=script_list_link(params[:site], params[:sort], params[:site], @set)%>
				<% end %>
				<li><%= link_to t('scripts.listing_filter_by_site_more_sites'), site_list_scripts_path %></li>
			</ul>
		</div>
	<% end %>

	<% # This doesn't work for search
	if action_name != 'search' && user_signed_in? && !current_user.script_sets.empty? %>
		<div id="script-list-set" class="list-option-group">Script set:
			<ul>
				<%=script_list_link('All', params[:sort], params[:site], nil, @set)%>
				<% ScriptSet.favorites_first(current_user.script_sets).each do |set| %>
					<%=script_list_link(set.display_name, params[:sort], params[:site], set.id, @set)%>
				<% end %>
			</ul>
		</div>

	<% end %>
</div>

